package tool

import play.api.data._
import play.api.data.Forms._
import tool.Pojo._

/**
 * Created by yz on 2018/6/12
 */

class FormTool {

  case class DeleteMisiionData(missionId: Int, kind: String)

  val deleteMissionForm = Form(
    mapping(
      "missionId" -> number,
      "kind" -> text
    )(DeleteMisiionData.apply)(DeleteMisiionData.unapply)
  )

  case class MissionIdData(missionId: Int)

  val missionIdForm = Form(
    mapping(
      "missionId" -> number
    )(MissionIdData.apply)(MissionIdData.unapply)
  )

  case class MissionData(missionName: String, kind: String)

  val missionForm = Form(
    mapping(
      "missionName" -> text,
      "kind" -> text
    )(MissionData.apply)(MissionData.unapply)
  )

  case class MissionFileData(missionId: Int, fileName: String)

  val missionFileForm = Form(
    mapping(
      "missionId" -> number,
      "fileName" -> text
    )(MissionFileData.apply)(MissionFileData.unapply)
  )

  case class IframeData(html: String)

  val iframeForm = Form(
    mapping(
      "html" -> text
    )(IframeData.apply)(IframeData.unapply)
  )

  case class KindData(kind: String)

  val kindForm = Form(
    mapping(
      "kind" -> text
    )(KindData.apply)(KindData.unapply)
  )

  case class CAnaData(method: String)

  val cAnaForm = Form(
    mapping(
      "method" -> text
    )(CAnaData.apply)(CAnaData.unapply)
  )

  case class SvgData(svgHtml: String)

  val svgForm = Form(
    mapping(
      "svgHtml" -> text
    )(SvgData.apply)(SvgData.unapply)
  )

  case class FileNameData(fileName: String)

  val fileNameForm = Form(
    mapping(
      "fileName" -> text
    )(FileNameData.apply)(FileNameData.unapply)
  )



  case class AdminData(account: String, password: String)

  val adminForm = Form(
    mapping(
      "account" -> text,
      "password" -> text
    )(AdminData.apply)(AdminData.unapply)
  )

  case class GeneWiseData(proteinMethod: String, proteinText: String, dnaMethod: String, dnaText: String, para: Boolean,
                          pretty: Boolean, genes: Boolean, trans: Boolean, cdna: Boolean, embl: Boolean, ace: Boolean,
                          gff: Boolean, diana: Boolean, init: String, splice: String, random: String, alg: String)

  val geneWiseForm = Form(
    mapping(
      "proteinMethod" -> text,
      "proteinText" -> text,
      "dnaMethod" -> text,
      "dnaText" -> text,
      "para" -> boolean,
      "pretty" -> boolean,
      "genes" -> boolean,
      "trans" -> boolean,
      "cdna" -> boolean,
      "embl" -> boolean,
      "ace" -> boolean,
      "gff" -> boolean,
      "diana" -> boolean,
      "init" -> text,
      "splice" -> text,
      "random" -> text,
      "alg" -> text
    )(GeneWiseData.apply)(GeneWiseData.unapply)
  )

  case class MuscleData(method: String, text: String, tree: String)

  val muscleForm = Form(
    mapping(
      "method" -> text,
      "text" -> text,
      "tree" -> text
    )(MuscleData.apply)(MuscleData.unapply)
  )

  case class MissionNameData(missionName: String)

  val missionNameForm = Form(
    mapping(
      "missionName" -> text
    )(MissionNameData.apply)(MissionNameData.unapply)
  )


}

object FormTool {

  val deleteMissionForm = Form(
    mapping(
      "missionId" -> number,
      "kind" -> text
    )(DeleteMisiionData.apply)(DeleteMisiionData.unapply)
  )

  val kindForm = Form(
    mapping(
      "kind" -> text
    )(KindData.apply)(KindData.unapply)
  )

  val missionIdForm = Form(
    mapping(
      "missionId" -> number
    )(MissionIdData.apply)(MissionIdData.unapply)
  )

  val missionForm = Form(
    mapping(
      "missionName" -> text,
      "kind" -> text
    )(MissionData.apply)(MissionData.unapply)
  )

  val muscleForm = Form(
    mapping(
      "queryText" -> optional(text),
      "tree" -> text
    )(MuscleData.apply)(MuscleData.unapply)
  )

  val svgForm = Form(
    mapping(
      "svgHtml" -> text
    )(SvgData.apply)(SvgData.unapply)
  )

  val missionNameForm = Form(
    mapping(
      "missionName" -> text
    )(MissionNameData.apply)(MissionNameData.unapply)
  )

  val missionFileForm = Form(
    mapping(
      "missionId" -> number,
      "fileName" -> text
    )(MissionFileData.apply)(MissionFileData.unapply)
  )

  val userForm = Form(
    mapping(
      "name" -> text,
      "password" -> text
    )(UserData.apply)(UserData.unapply)
  )

  val userNameForm = Form(
    mapping(
      "name" -> text
    )(userNameData.apply)(userNameData.unapply)
  )

  val idForm = Form(
    mapping(
      "id" -> number
    )(IdData.apply)(IdData.unapply)
  )

  val sampleNameForm = Form(
    mapping(
      "sampleName" -> text
    )(SampleNameData.apply)(SampleNameData.unapply)
  )

  val orthoMclForm = Form(
    mapping(
      "pvCutoff" -> text,
      "piCutoff" -> text,
      "pmatchCutoff" -> text
    )(OrthoMclData.apply)(OrthoMclData.unapply)
  )

  val crisprForm = Form(
    mapping(
      "method" -> text,
      "queryText" -> text,
      "minDR" -> text,
      "maxDR" -> text,
      "percSPmin" -> text,
      "percSPmax" -> text,
      "spSim" -> text,
      "mismDRs" -> text,
      "truncDR" -> text,
      "flank" -> text,
      "arm" -> optional(text),
      "dt" -> optional(text),
      "cas" -> optional(text),
      "defValue" -> text,
      "meta" -> optional(text)
    )(CrisprData.apply)(CrisprData.unapply)
  )

  val vfdbForm = Form(
    mapping(
      "method" -> text,
      "queryText" -> text,
      "seqType" -> text,
      "evalue" -> text,
      "maxTargetSeqs" -> text
    )(VfdbAnnoData.apply)(VfdbAnnoData.unapply)
  )

  val pfamForm = Form(
    mapping(
      "method" -> text,
      "queryText" -> text,
      "seqCutoff" -> text,
      "domainCutoff" -> text
    )(PfamAnnoData.apply)(PfamAnnoData.unapply)
  )

  val predictForm = Form(
    mapping(
      "method" -> text,
      "queryText" -> text,
      "shape" -> text,
    )(PredictData.apply)(PredictData.unapply)
  )

  val ardbForm = Form(
    mapping(
      "method" -> text,
      "queryText" -> text,
      "evalue" -> text
    )(ArdbAnnoData.apply)(ArdbAnnoData.unapply)
  )

  val cazyForm = Form(
    mapping(
      "method" -> text,
      "queryText" -> text
    )(CazyAnnoData.apply)(CazyAnnoData.unapply)
  )

  val annoForm = Form(
    mapping(
      "method" -> text,
      "queryText" -> text,
      "annoMethods" -> seq(text),
      "dbKind" -> text,
      "eValue" -> text,
      "maxTargetSeqs" -> text
    )(AnnoData.apply)(AnnoData.unapply)
  )

  val changePasswordForm = Form(
    mapping(
      "password" -> text,
      "newPassword" -> text
    )(ChangePasswordData.apply)(ChangePasswordData.unapply)
  )

  val loginUserForm = Form(
    mapping(
      "name" -> text,
      "password" -> text
    )(LoginUserData.apply)(LoginUserData.unapply)
  )


}
